import plugin from '../../lib/plugins/plugin.js'
import fetch from 'node-fetch'
import { segment } from 'oicq'
import yaml from "yaml"
import fs from 'node:fs'
import request from 'request'

let agent = 'i.acgmx.com'; //代理地址

export class calc extends plugin {
  constructor() {
    super({
      /** 功能名称 */
      name: '兽语加密',
      /** 功能描述 */
      dsc: '兽语加密解密',
      /** https://oicqjs.github.io/oicq/#events */
      event: 'message',
      /** 优先级，数字越小等级越高 */
      priority: 2001,
      rule: [
        {
            /** 命令正则匹配 */
            reg: '^#兽语加密 ?.*',
            /** 执行方法 */
            fnc: 'jiami',
        },
        {
          /** 命令正则匹配 */
          reg: '^#兽语解密 ?.*',
          /** 执行方法 */
          fnc: 'jiemi',
      },
      ]
    })
  }

  async jiami(e){
    let emsg = e.msg.replace(/#兽语加密 ?/,'');
    let url = `http://ovooa.com/API/sho_u/?type=text&msg=${emsg}`;
    let res = await fetch(encodeURI(url));
    res = await res.text();
    e.reply(`加密结果：\n${res}`);
    return true;
  }
  
  async jiemi(e){
    let emsg = e.msg.replace(/#兽语解密 ?/,'');
    let url = `http://ovooa.com/API/sho_u/?type=text&format=1&msg=${emsg}`;
    let res = await fetch(encodeURI(url));
    res = await res.text();
    e.reply(`解密结果：\n${res}`);
    return true;
  }
}